package com.ruoyi.crop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.crop.api.domain.Farmer;
import com.ruoyi.crop.service.FarmerService;
import com.ruoyi.crop.mapper.FarmerMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 86178
* @description 针对表【src_farmer(农户管理表)】的数据库操作Service实现
* @createDate 2024-07-27 09:35:55
*/
@Service
public class FarmerServiceImpl extends ServiceImpl<FarmerMapper, Farmer>
    implements FarmerService{

    /**
     * 获取农户管理列表
     */
    @Override
    public List<Farmer> selectFarmerList(Farmer farmer) {
        return baseMapper.selectFarmerList(farmer);
    }

    /**
     * 校验农户名称
     * @param farmer
     * @return
     */
    @Override
    public boolean checkFarmerNameUnique(Farmer farmer) {
        LambdaQueryWrapper<Farmer> queryWrapper = new LambdaQueryWrapper<>();
        if (farmer!=null){
            queryWrapper.eq(StringUtils.isNotBlank(farmer.getFarmerName()),Farmer::getFarmerName,farmer.getFarmerName());
        }
        Farmer one = this.getOne(queryWrapper);
        if (StringUtils.isNotNull(one)){
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}




